<?php

use Illuminate\Support\Arr;

if (!function_exists('log_daily')) {
    function log_daily($name = 'lumen')
    {
        return new Monolog\Logger('lumen', [
            (new Monolog\Handler\StreamHandler(dirname(__DIR__) . '/storage/logs/' . date('Y-m-d') . '/' . $name . '.log', Monolog\Logger::DEBUG))
                ->setFormatter(new Monolog\Formatter\LineFormatter(null, null, true, true))
        ]);
    }
}

if (!function_exists('aes_cbc_encrypt')) {
    // 加密程序
    function aes_cbc_encrypt($data, $iv = 'c81e728d9d4c2f63')
    {
        $key = 'c4ca4238a0b923820dcc509a6f75849b'; //32位
        // $iv  = 'c81e728d9d4c2f63'; //16位
        return base64_encode(openssl_encrypt($data, 'AES-256-CBC', $key, OPENSSL_RAW_DATA, $iv));
    }
}

if (!function_exists('aes_cbc_decrypt')) {
    // 解密程序
    function aes_cbc_decrypt($data, $iv = 'c81e728d9d4c2f63')
    {
        $key = 'c4ca4238a0b923820dcc509a6f75849b'; //32位
        // $iv  = 'c81e728d9d4c2f63'; //16位
        return openssl_decrypt(base64_decode($data), 'AES-256-CBC', $key, OPENSSL_RAW_DATA, $iv);
    }
}

if (!function_exists('create_secret')) {
    function create_secret()
    {
        $ary = array_merge(range('a', 'z'), range(0, 9), [microtime(true)]);
        shuffle($ary);
        shuffle($ary);
        shuffle($ary);
        return strtoupper(md5(implode('', $ary)));
    }
}

if (!function_exists('array_set')) {
    /**
     * Set an array item to a given value using "dot" notation.
     *
     * If no key is given to the method, the entire array will be replaced.
     *
     * @param array $array
     * @param string $key
     * @param mixed $value
     * @return array
     */
    function array_set(&$array, $key, $value)
    {
        return Arr::set($array, $key, $value);
    }
}

if (!function_exists('array_get')) {
    /**
     * Get an item from an array using "dot" notation.
     *
     * @param array $array
     * @param string $key
     * @param mixed $default
     * @return mixed
     */
    function array_get($array, $key, $default = null)
    {
        return Arr::get($array, $key, $default);
    }
}

if (!function_exists('array_forget')) {
    /**
     * Remove one or many array items from a given array using "dot" notation.
     *
     * @param array $array
     * @param array|string $keys
     * @return void
     */
    function array_forget(&$array, $keys)
    {
        return Arr::forget($array, $keys);
    }
}

